package com.donger.business.storage.config;

import cn.hutool.core.date.DateUtil;
import com.donger.common.sequence.builder.DbSeqBuilder;
import com.donger.common.sequence.properties.SequenceDbProperties;
import com.donger.common.sequence.sequence.Sequence;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author aeizzz
 * <p>
 * 设置发号器生成规则
 */
@Configuration
public class SequenceConfig {


    @Bean
    public Sequence fileSequence(DataSource dataSource,
                                 SequenceDbProperties properties){
        return DbSeqBuilder
                .create()
                .bizName(() -> String.format("file_%s", DateUtil.today()))
                .dataSource(dataSource)
                .step(properties.getStep())
                .retryTimes(properties.getRetryTimes())
                .tableName(properties.getTableName())
                .build();
    }
}
